var g_Interval = 1;
var g_PersonCount = 500;//参加抽奖人数
var g_Timer;
var running = false;
var resultBack="";
var resultEntity=[];
function beginRndNum(trigger){
	if(running){
		getResultTimes = getResultTimes +1;
		running = false;
		clearTimeout(g_Timer);
		if(resultEntity.length==0){
			alert("亲，奖池已经没人了啊~~~");
			$('#ResultNum').html("000");
		}
		resultBack="";
		for(var i=0;i<resultEntity.length;i++){
			$("#result").append("<li  class='"+resultLiClass+"' title='"+resultEntity[i].name+"'>"+resultEntity[i].lotteryNumber+"</li>");
			if(i==resultEntity.length-1){
				$('#ResultNum').html(resultEntity[i].lotteryNumber);
			}
		}
	}
	else{
		running = true;
		var url = "/osyear/api/qrcode/getAwardList";
			//这里去后台拿获奖人员抽奖券号，放入前台显示
			$.ajax({
				url:url,
				type: "post",
				dataType :"json",
				async:false,
				data:{
					awardid: $("#awardid").val(),
					votes:$("#awardid").attr("votes")
				},
				success: function (data) {
					if(data.data){
						resultEntity = data.data;

						//resultBack = data.data[0].lotteryNumber;
					}
				},
				error: function () {
				}

			});
		beginTimer();
		
	}
}

function updateRndNum(){
	var num = Math.floor(Math.random()*g_PersonCount+1);
	if(num<10){
	num = "00"+num;
	}else if(num<100){
	num = "0"+num;
	}
	$('#ResultNum').html(num);
	
}

function beginTimer(){
	g_Timer = setTimeout(beat, g_Interval);
	
}

function beat() {
	g_Timer = setTimeout(beat, g_Interval);
	updateRndNum();
	
}
/**
 * 格式化REST风格URL，多个参数将以/拼接
 * 示例: formatUrl("/index",user,tom)</br>
 * 格式化后输出结果为：http://{host}/{root}/index/user/tom
 * @param url 资源路径地址
 * @returns {string}
 */
function formatRestUrl(url) {
	var _url = getRootPath();
	_url = 0 === url.indexOf("/") ? (_url + url.replace("/", "")) : (_url + url);
	for (i in arguments) {
		if (i < 1) continue;
		if (arguments[i] && "string" === typeof (arguments[i])) {
			_url += "/" + arguments[i];
		}
	}
	return encodeURI(_url);
}